/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

HCM.CreateHIT = new (function() {
    var j_root_el;
    var firstStepLink;
    var secondStepLink;
    var firstStepContainer;
    var secondStepContainer;
    var errorMessageContainer;

    this.onReady = function(el) {
        j_root_el = $(el);
        firstStepLink = j_root_el.find('a.step1');
        secondStepLink = j_root_el.find('a.step2');
        firstStepContainer = j_root_el.find('#tab-1');
        secondStepContainer = j_root_el.find('#tab-2');
        errorMessageContainer = j_root_el.find('.errorSummary');

        secondStepLink.click(function(){
            return validateClientCampgin(firstStepContainer);
        });
    };

    // root is a JQuery object
    var validateClientCampgin = function(root) {
        if (root) {
            var client_el = root.find('#ddl_clientkey');
            var campaign_el = root.find('#ddl_campaignkey');
            try {
                if (client_el.val() == 0 || campaign_el.val() == null) {
                    errorMessageContainer.html('Please select client and campaign before you continue next step.');
                    errorMessageContainer.show();
                    return false;
                } else {
                    errorMessageContainer.hide();
                    return true;
                }
            } catch (e) {
            // do nothing
            }
        }

        return false;
    }
});

$(function(){
    HCM.CreateHIT.onReady($('.tabs').get(0));
});